package com.wtx.chapter02;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;


/**
 * @description:
 * @author: wtx
 * @createDate: 2020/5/29
 */
public class MyClientHandler extends SimpleChannelInboundHandler<String> {
    //收到服务端的消息就调用这个方法
    protected void channelRead0(ChannelHandlerContext ctx, String s) throws Exception {
        System.out.println(ctx.channel().remoteAddress()+" "+s);
        ctx.writeAndFlush("from client: "+ System.currentTimeMillis());
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush("来自客户端的问候");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}
